


<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@page import="server.entity.Category"%>
<%@page import="server.process.ProcessBeanLocal"%>
<%@page import="javax.naming.InitialContext"%>
<%@page import="javax.naming.Context"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Web Photo Share</title>
        <link rel="stylesheet" href="style.css" type="text/css"/>
        <script type="text/javascript" src="js/jquery-1.6.2.min.js"></script>
        <script type="text/javascript">
            var Error="<img src='image/icon/png/error.png' alt='error'/>"
            var OK="<img src='image/icon/png/ok.png' alt='error'/>"
            function validate(){
                var result=true;
                if ($.trim($('#imagename').val())==""){
                    $("#err2").html(Error);
                    result=false;
                }else{
                    $("#err2").html(OK);
                }
                if ($.trim($('#imageDescription').val())==""){
                    $("#err3").html(Error);
                    result=false;
                }else{
                    $("#err3").html(OK);
                }
                if ($.trim($('#tags').val())==""){
                    $("#err4").html(Error);
                    result=false;
                }else{
                    $("#err4").html(OK);
                }
                if ($.trim($('#fileupload').val())==""){
                    $("#err1").html(Error);
                    result=false;
                }else {
                    var index=$('#fileupload').val().lastIndexOf(".");
                    var fileExt=$('#fileupload').val().substr(index+1);
                    var imgext=["jpg","jpeg","png","gif"];
                    var check = false;
                    var x;
                    for (x in imgext ){
                        var patt = new RegExp(imgext[x],"i");
                        if (patt.test(fileExt)){
                            check=true;
                            break;
                        }
                    }
                    if (check==false){
                        $("#err1").html(Error);
                        $("#exterr").html("Image file support jpg,jpeg,png,gif");
                    }else{
                        $("#err1").html(OK);
                    }
                }
                return result;
            }
            function initilise(){
                $("#commentform").hide();
            }
            $(document).ready(function(){
                t=setInterval('validate()', 1000);
                $("#btsubmit").click(function(){
                    if (validate()==false){
                        return false;
                    }else{
                        clearInterval(t);
                        return true;
                    }
                });
                $("input:radio[name=type]").click(function() {
                    var value = $(this).val();
                    if (value=="public"){
                        $.ajax({
                            type:"POST",
                            url:"doCollection",
                            data:"action=getListPublic",
                            complete:function(data){
                                $("#slCollection").html(data.responseText);
                            }
                        }) ;
                    }else{
                        $.ajax({
                            type:"POST",
                            url:"doCollection",
                            data:"action=getListPrivate",
                            complete:function(data){
                                $("#slCollection").html(data.responseText);
                            }
                        }) ;
                    }
                });
            });
        </script>
    </head>
    <body>
        <div id="wrapper">
            <div id="header">

                <h1>Photo Share</h1>
                <img src="header_right.gif" alt="hinh"/>
            </div>
            <div id="nav">
                <ul>
                    <li><a href="index.jsp">Home</a></li>
                    <li><a href="allcollection.jsp">Manage Collection</a></li>
                    <li><a href="allimage">Manage Image</a></li>
                    <li><a href="upload.jsp">Upload</a></li>
                    <li><a href="faq.jsp">FAQs</a></li>
                    <li class="end"><a href="contactus.jsp">Contact</a></li>
                </ul>
            </div>
            <div id="main">
                <div id="slidebar">
                    <div id="login">
                        <jsp:include page="login.jsp"></jsp:include>
                    </div>
                    <div id="search">
                        <jsp:include page="search.jsp"></jsp:include>
                    </div>
                    <div id="product">
                        <jsp:include page="categorypanel.jsp"></jsp:include>
                    </div>
                </div>
                <div id="content">
                    <a href="#">Home</a>-><a href="#">My Collection</a>-><a href="#">Upload Image</a>
                    <br/>
                    <h2>Upload Image</h2>
                    <br/>
                    <form action="doUpload" id="frupload" method="POST" enctype="multipart/form-data">
                        <table border="0">
                            <tr>
                                <td colspan="2"><input type="file" name="photoupload" id="fileupload" value="" /><span id="err1"></span></td>
                                <td id="exterr"></td>
                            </tr>
                            <tr>
                                <td>Image Name</td>
                                <td><input type="text" name="txtName" id="imagename" value=""/><span id="err2"></span></td>
                            </tr>
                            <tr>
                                <td>Image Description</td>
                                <td><input type="text" name="txtDescription" id="imageDescription" value=""/><span id="err3"></span></td>
                            </tr>
                            <tr>
                                <td>Tag</td>
                                <td><input type="text" name="tag" id="tags" value=""/><span id="err4"></span></td>
                            </tr>
                            <tr>
                                <td>Collection</td>
                                <td><input type="radio" name="type" id="private" checked="checked" value="public"/>Private <input name="type" id="public" type="radio" value="private" />Public</td>
                            </tr>
                            <tr>
                                <td>Collection Name</td>
                                <td><select name="slCollection" id="slCollection">

                                    </select></td>
                            </tr>
                            <tr>
                                <td><input type="submit" name="action" value="Upload"/></td>
                            </tr>
                        </table>
                        <div id="result">
                            <c:if test="${SUCCESS==1}">
                                
                                    <table>
                                        <tr colspan="2">
                                            <td><img alt=""  src="imageurl"/></td>
                                            <td>View link: <input type="text" value=""/></td>
                                        </tr>
                                        <tr>
                                            <td></td>
                                            <td>Download link: <input type="text" value=""/></td>
                                        </tr>
                                    </table>
                                
                            </c:if>
                        </div>
                    </form>
                    <div id="UploadERR">${UploadERR}</div>
                    <div id="SUCCESS">${SUCCESS}</div>
                </div>
            </div>
            <div id="footer">

            </div>
        </div>
    </body>
</html>
